package com.ilovepostcard;

import java.io.Serializable;
import java.util.ArrayList;

import com.ilovepostcard.model.Postcard;
import com.ilovepostcard.view.PostcardGridView;
import com.ilovepostcard.view.PostcardGridView.OnPostcardClickListener;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;

public class SelectPostCardActivity extends BaseActivity implements OnClickListener{
	
	
	Button confirm;
	PostcardGridView pcList;
	ImageView mReturn;
	@Override
    public void onCreate(Bundle savedInstanceState) {
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_selectpc);
		init();
	}
	
	private void init()
	{
		confirm = (Button)findViewById(R.id.confirm);
		confirm.setOnClickListener(this);
		
		pcList = (PostcardGridView)findViewById(R.id.discover_recommend);
		pcList.setMultiSelectMode();
		pcList.loadNextPage();
		
		mReturn = (ImageView)findViewById(R.id.title_return);
		mReturn.setOnClickListener(this);
		
	}

	@Override
	public void onClick(View v) {
		if(v.getId() ==  R.id.confirm)
		{
			Intent data = new Intent();
			com.ilovepostcard.model.Postcard[] orgData = pcList.getSelectedPostcard();
			
			ArrayList<com.ilovepostcard.model.Postcard> list = new ArrayList<com.ilovepostcard.model.Postcard>();
			for(int i =0;i<orgData.length;i++)
			{
				if(orgData[i] != null)
					list.add(orgData[i]);
			}
			data.putExtra("postcard",(Serializable)list);
            setResult(Activity.RESULT_OK, data);
            
            finish();
		}
		else if(v.getId() == R.id.title_return)
		{
			finish();
		}
		
	}

}
